<%--
  Created by IntelliJ IDEA.
  User: 王辉
  Date: 2022/5/10
  Time: 18:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.lang.*" %>
<% request.setCharacterEncoding("UTF-8");%>
<html>
<head>
    <title>修改完成</title>
</head>
<body>
<%
String driverName="com.mysql.cj.jdbc.Driver";
String username = "root";
String password = "123456";
String url = "jdbc:mysql://localhost:3306/t_card?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false";
Class.forName(driverName);
Connection conn = DriverManager.getConnection(url,username,password);
String sql = "update cuser set cname = ?,csex = ?,cphone = ?,cemail = ? where cid = ?";
Integer cid = (Integer) session.getAttribute("cid");
String sql2 = "select id from user where username = ?";
PreparedStatement pstmt1 = conn.prepareStatement(sql);
PreparedStatement pstmt2 = conn.prepareStatement(sql2);
String userName = (String) session.getAttribute("username");
pstmt2.setString(1,userName);
ResultSet rs1 = pstmt2.executeQuery();
String uid = "";
while (rs1.next()){
uid = rs1.getString("id");
}
String cUserName = request.getParameter("cUserName");
String cSex = request.getParameter("cSex");
String cPhone = request.getParameter("cPhone");
String cEmail = request.getParameter("cEmail");
pstmt1.setString(1,cUserName);
pstmt1.setString(2,cSex);
pstmt1.setString(3,cPhone);
pstmt1.setString(4,cEmail);
pstmt1.setInt(5,cid);
int result = pstmt1.executeUpdate();
if(result==1){
%>
<div align="center"><h1 style="color: crimson">修改成功</h1><br><br>
    <a href="index.jsp" style="color: chartreuse">返回主页</a><br><br><br>
    <a href="updatecard.jsp" style="color: crimson">继续修改其他</a><br><br><br>
</div>

<%
    }else{
%>
<div align="center"><h1 style="color: crimson">修改失败</h1><br><br>
    <a href="index.jsp" style="color: chartreuse">返回主页</a><br><br><br>
    <a href="updatecard.jsp" style="color: crimson">继续修改</a><br><br><br>
</div>
<%
    }
%>
</body>
</html>
